// pages/newfirm/newfirm.js
var app = getApp()
var getlist = function (that) {
    app.getApi.request("/api/CompanyDriverApplyOrInviteAssociate/List", { drivers: { id: app.getApi.drivers.id, name: app.getApi.drivers.name, tel: app.getApi.drivers.tel }, pageIndex: that.data.pageIndex, pageSize: 10 }, "POST", (res) => {
        if (res.data.responseCode == 1000) {
            if (res.data.obj.length > 0) {
                that.setData({
                    AllVehicles: that.data.AllVehicles.concat(res.data.obj)
                })
            }
            if (that.data.pageIndex > 1 && res.data.obj.length == 0) {
                that.setData({
                    isAll: true
                })
            }
            if (that.data.pageIndex == 1 && res.data.obj.length == 0) {
                that.setData({
                    noData: true
                })
            }
        } else {
            wx.showToast({
                title: '请求失败',
                icon: 'loading',
                duration: 2000
            });
        }
    }, (res) => { })
}
Page({

    /**
     * 页面的初始数据
     */
    data: {
        pageIndex: 1,
        AllVehicles: [],
        isAll: false,
        noData: false,
        hidden: false,
        Pullcount: 0,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onShow: function (options) {
        var that = this
        getlist(that)
        that.setData({
            AllVehicles: [],
            isAll: false,
            noData: false,
            hidden: false,
            Pullcount: 0
        })
    },
    onReachBottom() {
        var that = this
        if (!that.data.isAll && that.data.Pullcount == 0) {
            that.setData({
                pageIndex: that.data.pageIndex + 1
            })
            that.page = that.page + 1
            that.loadMore = true
            getlist(that)
        } else {
            that.isAll = true
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    add: function (e) {
        var that = this
        app.getApi.request("/api/CompanyDriverApplyOrInviteAssociate/ComfirmInvite", { applyOrInviteIdList: [e.currentTarget.dataset.id] }, "POST", (res) => {
            if (res.data.responseCode == 1000) {
                wx.showToast({
                    title: "加入成功",
                    icon: 'success',
                    duration: 2000,
                });
            } else {
                wx.showToast({
                    title: '请求失败',
                    icon: 'loading',
                    duration: 2000
                });
            }
        }, (res) => { })
    },

    /**
     * 生命周期函数--监听页面显示
     */

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },


    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})